#pragma once

#include "../QDrawCell/qbasedrawcell.h"
#include "../QDraw.h"

#include <string>

QNamespaceStart(Qui)

typedef enum QLabelTextPosition
{
	TextLocatedLeft,    TextLocatedRight, TextLocateCenter,
	TextLocatedCentral, TextLocatedXY
} QFontTextPosition;

class QFontDrawCell
	: public QDrawCellBase
{
	private:
		LOGFONT		   current_log_font;
		LOGFONT		   font_style;

		QFontTextPosition text_position;

	private:
		IMAGE   font_image;

		std::wstring text_string;

		bool    show_image = true;

	private:
		void _init_font_style()
		{
			gettextstyle(&current_log_font);

			font_style = current_log_font;
		}

	public:
		QFontDrawCell()
		{
			_init_font_style();

			text_position = TextLocatedLeft;

			text_string = L"";

			QGetimage(get_x(), get_y(), get_width(), get_height(), &background);

			font_image  = IMAGE(get_width(), get_height());
		}
		QFontDrawCell(std::wstring string, QSize_t geomtery, LOGFONT font)
		{
			_init_font_style();

			text_position = TextLocatedLeft;

			font_style  = font;
			text_string = string;

			set_width(geomtery.width);
			set_height(geomtery.height);
			set_x(geomtery.x);
			set_y(geomtery.y);

			QGetimage(get_x(), get_y(), get_width(), get_height(), &background);

			font_image = IMAGE(get_width(), get_height());
		}
		QFontDrawCell(std::wstring string, QSize_t geomtery, int font = NULL)
		{
			_init_font_style();

			text_position = TextLocatedLeft;

			text_string = string;

			set_width(geomtery.width);
			set_height(geomtery.height);
			set_x(geomtery.x);
			set_y(geomtery.y);

			QGetimage(get_x(), get_y(), get_width(), get_height(), &background);

			font_image = IMAGE(get_width(), get_height());
		}

	public:
		void draw();
		void set_text(std::wstring string)
		{
			text_string = string;
		}

		IMAGE get_font_image()
		{
			return font_image;
		}

		void reset_image()
		{
			font_image = IMAGE(get_width(), get_height());
		}

		void put_image(bool show)
		{
			show_image = show;
		}

		void set_position(QFontTextPosition position)
		{
			text_position = position;
		}

		void set_font_style(LOGFONT font)
		{
			font_style = font;
		}

	public:
		void appy_font_style()
		{
			settextstyle(&font_style);
		}
		void restore_font_style()
		{
			settextstyle(&current_log_font);
		}

		LPCTSTR get_text()
		{
			return text_string.c_str();
		}
};
QNamespaceEnd